package com.ruoyi.system.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.athleteTrapTargetDto;
import com.ruoyi.system.domain.vo.athleteTrapTargetVo;
import com.ruoyi.system.domain.vo.athleteTrapVo;
import com.ruoyi.system.service.athleteTrapService;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/trap")
public class athleteTrap {

    @Resource
    private athleteTrapService trapService;
    @GetMapping
    public AjaxResult getTrapScore(@Param("athleteTrapVo") athleteTrapVo athleteTrapVo){
        System.out.println(athleteTrapVo.getId());
        if (athleteTrapVo.getStartDay() == null || athleteTrapVo.getEndDay() == null){
            LocalDate thirtyDaysAgo = LocalDate.now().minusDays(30);
            Date date = Date.from(thirtyDaysAgo.atStartOfDay(ZoneId.systemDefault()).toInstant());
            athleteTrapVo.setStartDay(date);
            athleteTrapVo.setEndDay(new Date());
        }
        return AjaxResult.success(trapService.getTrapByDate(athleteTrapVo));
    }

    @GetMapping("/daytarget")
    public AjaxResult getDayTarget(@Param("athleteTrapTargetVo") athleteTrapTargetVo athleteTrapTargetVo){
        if (athleteTrapTargetVo.getTraindate() == null){
            athleteTrapTargetVo.setTraindate(new Date());
        }
        List<athleteTrapTargetDto> trainingStatsByDateAndId = trapService.getTrainingStatsByDateAndId(athleteTrapTargetVo);
        return AjaxResult.success(trainingStatsByDateAndId);
    }
}
